package com.googlecode.bip.xml.export;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.naming.NamingException;
import org.apache.log4j.Logger;

/**
 *
 *
 * @author Claude CHOISNET
 */
//not public
class XMLSurveyEntryFactoryBuilder<T>
{
    private final static Logger logger = Logger.getLogger( XMLSurveyEntryFactoryBuilder.class );
    private XMLSurveyConnection connection;
    private String sql;
    private List<T> list = new ArrayList<T>();

    /**
     *
     * @param xmlSurveyConnection
     */
    public XMLSurveyEntryFactoryBuilder(
            XMLSurveyConnection connection,
            String          sql
            )
    {
        this.connection = connection;
        this.sql        = sql;
    }

    /**
     *
     * @return
     * @throws SQLException
     * @throws NamingException
     */
    protected XMLSurveyConnection.ResultSetCache execute(String...rows)
        throws SQLException, NamingException
    {
        logger.info( "sql = " + sql );

        return connection.executeQuery( sql, rows );

//        ResultSet       rset    = connection.executeQuery( sql );
//        ResultSetCache  cache   = new ResultSetCache();
//
//        while( rset.next() ) {
//            for( String r:rows ) {
//                cache.put( r, rset.getString( r ) );
//                }
//            cache.prepareNext();
//            }
//
//        rset.close();
//
//        return cache;
    }

    protected boolean add( T entry )
    {
        return list.add( entry );
    }

    protected List<T> getList()
    {
        return list;
    }
}
